@echo off

REM 获取当前分支名
for /f "delims=" %%a in ('git symbolic-ref --short HEAD') do set branch_name=%%a

REM 检查是否在仓库目录下
if not exist .git (
    echo Error: Not a git repository.
    exit /b 1
)

REM 添加所有更改到暂存区
git add .

REM 检查是否有任何文件被添加到暂存区
set first_file=true
for /f "delims=" %%i in ('git diff-index --cached --name-only HEAD --') do (
    set "first_file="
)

if defined first_file (
    echo No changes to commit.
    exit /b 0
)

REM 提交更改，使用命令行参数作为提交消息
if "%~1" == "" (
    echo Please provide a commit message:
    set /p message=
) else (
    set "message=%~1"
)

git commit -m "%message%"

REM 推送至远程仓库，默认推送到与当前分支同名的远程分支
git push origin "%branch_name%"

exit /b 0